var baseImageUrl = "http://api.freebase.com/api/trans/raw/guid/";
var servletUrl = "http://localhost:8080/MoteurExtractionInformation/wrapper";

$(document).ready(function(){
	setCSS();
	btnSearchClick();
	//setSlider();	
	$("#myinput").suggest().bind("fb-select", function(e, data){
		  //$("#idInput").val(data.id);
		  //$("#valInput").val(data.name);
		  getImages(data.name, data.id);
		  getDescription(data.name, data.id);
	});
	//loadContent();
});

function setCSS(){
	$("#myinput").suggest({
		  "css": {
		    "pane": "myPane",
		    "item": "myPane"
		  }
		});
}

function btnSearchClick(){
	$("#btnSearch").bind("click", function(){		
	});
}

function getImages(name, id){
	$("#largeImage").attr('src', "");
	$("#imageListItems").empty();
    $.ajax({
        url: servletUrl,  
        type:"post",
        dataType: "json",
        data: {
            op: 'getimages',
            name: name,
            id: id
        },
        success: function(response){
            imageUrl = baseImageUrl + response[0].guid.replace('#', '');
            $("#largeImage").attr('src', imageUrl);
            
            $.each(response, function(){
            	imageUrl = baseImageUrl + $(this)[0].guid.replace("#", '');
            	$("#imageListItems").append('<li><a src="#"><img src= "' + imageUrl + '"' +   
            			'width="75" height="75" alt="" /></a></li> ');
            });
        },
        error: function(jqXHR, textStatus, errorThrown){
           // alert(textStatus);
        }						
    });		
}

function getDescription(name, id){
	$("#des").empty();
    $.ajax({
        url: servletUrl,  
        type:"post",
        dataType: "json",
        data: {
            op: 'getdescription',
            name: name,
            id: id
        },
        success: function(response){
            $("#des").text(response.des);        	
        },
        error: function(jqXHR, textStatus, errorThrown){
           alert(textStatus);
        }						
    });		
}

function setSlider(){
	$("#slider").nivoSlider();
}